/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package WS;

import BD.Modulos.BdConfig;
import Interfaces.BdException;
import Interfaces.ConfigInterface;
import Objects.Measure;
import Objects.Sex;
import Objects.Unit;
import WS.Respuestas.RespBdConfig;
import java.sql.SQLException;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.xml.ws.WebServiceContext;
/**
 *
 * @author armgarces
 */
@WebService(serviceName = "Configuracion")
public class Configuracion {    
    public final static int CHECK_SEX     = 0;   
    public final static int CHECK_UNIT    = 1;
    public final static int CHECK_MEASURE = 2;
    @Resource
    WebServiceContext wsContext; 
    /***************************************************************************/
    /******************************** MEASURE **********************************/
    /***************************************************************************/ 
    /**
     * 
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "loadMeasure")
    public synchronized Measure[] loadMeasure() throws BdException {        
        try{
            return (Measure[]) BdConfig.getInstance().load(new Measure());      
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "findMeasure")
    public synchronized Measure[] findMeasure(@WebParam(name = "find") String find) throws BdException {
        try{
            return (Measure[]) BdConfig.getInstance().find(new Measure(), find);                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param user
     * @param measure
     * @param operacion
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "saveMeasure")
    public synchronized boolean saveMeasure(@WebParam(name = "user") String user,
                                            @WebParam(name = "measure") Measure measure,
                                            @WebParam(name = "operacion") int operacion) throws BdException {
//        boolean boo = Validar.validar_Save_Measure(measure);
//        if (boo){
        try{       
            return BdConfig.getInstance().saveMeasure(user, operacion, measure);
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }       
        return false;
    }
    /**
     * 
     * @param measure
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "checkMeasure")
    public synchronized boolean checkMeasure(@WebParam(name = "measure") String measure) throws BdException {
        try{
            return BdConfig.getInstance().check(CHECK_MEASURE,measure);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }
    /**
     * 
     * @param user
     * @param measure
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "changeMeasure")
    public synchronized boolean changeMeasure(@WebParam(name = "user") String user,
                                              @WebParam(name = "measure") Measure measure) throws BdException {
        try{
            return BdConfig.getInstance().change(user,measure);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }
    /***************************************************************************/
    /********************************* UNIT ************************************/
    /***************************************************************************/    
    /**
     * 
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "loadUnit")
    public synchronized Unit[] loadUnit() throws BdException {
        try{
            return (Unit[]) BdConfig.getInstance().load(new Unit());                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "findUnit")
    public synchronized Unit[] findUnit(@WebParam(name = "find") String find) throws BdException {
        try{
            return (Unit[]) BdConfig.getInstance().find(new Unit(),find);                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param user
     * @param unit
     * @param operacion
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "saveUnit")
    public synchronized boolean saveUnit(@WebParam(name = "user") String user,
                                         @WebParam(name = "unit") Unit unit,
                                         @WebParam(name = "operacion") int operacion) throws BdException {
//        boolean boo = Validar.validar_Save_Unit(unit);
//        if (boo){
        try{                
            return BdConfig.getInstance().saveUnit(user, operacion, unit);
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }       
        return false;
    }
    /**
     * 
     * @param name
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "checkUnit")
    public synchronized boolean checkUnit(@WebParam(name = "name") String name) throws BdException {
        try{
            return BdConfig.getInstance().check(CHECK_UNIT,name);                
        }catch(BdException bde){
            //resp.setError(bde.getMessage());
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }
    /**
     * 
     * @param user
     * @param unit
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "changeUnit")
    public synchronized boolean changeUnit(@WebParam(name = "user") String user,
                                           @WebParam(name = "unit") Unit unit) throws BdException {
        try{
            return BdConfig.getInstance().change(user, unit);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    } 
    /***************************************************************************/
    /********************************* SEX *************************************/
    /***************************************************************************/    
    /**
     * 
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "loadSex")
    public synchronized Sex[] loadSex() throws BdException {
        try{
            return (Sex[]) BdConfig.getInstance().load(new Sex());                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param find
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "findSex")
    public synchronized Sex[] findSex(@WebParam(name = "find") String find) throws BdException {
        try{
            return (Sex[]) BdConfig.getInstance().find(new Sex(),find);                  
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }
        return null;
    }    
    /**
     * 
     * @param user
     * @param sex
     * @param operacion
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "saveSex")
    public synchronized boolean saveSex(@WebParam(name = "user") String user,
                                        @WebParam(name = "sex") Sex sex,
                                        @WebParam(name = "operacion") int operacion) throws BdException {
//        boolean boo = Validar.validar_Save_Sex(sex);
//        if (boo){
        try{                
            return BdConfig.getInstance().saveSex(user, operacion, sex);
        }catch(BdException bde){
            throw bde;
        } catch (SQLException ex) {
        }       
        return false;
    }
    /**
     * 
     * @param name
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "checkSex")
    public synchronized boolean checkSex(@WebParam(name = "name") String name) throws BdException {
        RespBdConfig resp = new RespBdConfig();
        try{
            return BdConfig.getInstance().check(CHECK_SEX,name);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }
    /**
     * 
     * @param user
     * @param sex
     * @return 
     * @throws Interfaces.BdException 
     */
    @WebMethod(operationName = "changeSex")
    public synchronized boolean changeSex(@WebParam(name = "user") String user,
                                          @WebParam(name = "sex") Sex sex) throws BdException {
        try{
            return BdConfig.getInstance().change(user, sex);                
        }catch(BdException bde){
            throw bde;
        }catch(SQLException e){             
        }
        return false;
    }      
}
